package com.mask.juc.v1.c_000;

/**
 * synchronized关键字
 * 对某个对象加锁
 * @author hx
 * @date 2021/10/11 9:57 上午
 */

public class T {
    private int count = 10;
    private Object o = new Object();

    public /*synchronized*/ void m(){  //相当于synchronized(T_AtomicInteger.class)
        synchronized (o){ //任何线程想要执行下面这段代码，必须先拿到o的锁
            count--;
            System.out.println("线程名:"+Thread.currentThread().getName()+",count = "+count);
        }
    }

    public static void main(String[] args) {
        new T().m();
    }
}
